//index.js
const app = getApp()
const db = wx.cloud.database()
Page({
  data: {
    uname:'',
    upwd:''
  },
  unameInput(e){
    this.setData({
      uname:e.detail.value
    })
  },
  upwdInput(e){
    this.setData({
      upwd:e.detail.value
    })
  },
  login() {
    console.log(this.data.uname,this.data.upwd)
    db.collection('users').where({
      uname: this.data.uname,
      upwd:this.data.upwd
    }).get().then(res => {
      const data = res.data[0]
      if (data.title && data.upwd == this.data.upwd && this.data.uname == data.uname) {
        app.globalData.userInfo = data;
        wx.switchTab({
          url: '/pages/mine/mine',
        })
      }
    }).catch(err=>{
      console.log(err)
      wx.showToast({
        title: '用户名或密码不正确',
        icon:'none'
      })
    })
  },
  onLoad: function () {

  },

})